package TencentCloud

import (
	"duoke/model"
	utils "duoke/utils/common"
	"duoke/utils/yaml"
	"encoding/json"
	"fmt"
)

// TencentStoreUtils 腾讯云市场 ai舌诊
var TencentStore = new(tencentStoreUtils)

type tencentStoreUtils struct {
	AppKey    int    `json:"AppKey"`
	AppSecret string `json:"AppSecret"`
	AppCode   string `json:"AppCode"`
}

func (s *tencentStoreUtils) NewConfig() *tencentStoreUtils {
	config := yaml.GetConfig()
	return &tencentStoreUtils{
		AppCode:   config.TencentTongueDiagnosis.AppCode,
		AppKey:    config.TencentTongueDiagnosis.AppKey,
		AppSecret: config.TencentTongueDiagnosis.AppSecret,
	}
}

var url = "https://ali-market-tongue-detect-v2.macrocura.com"

func (s *tencentStoreUtils) Result(req *model.Result) ([]byte, error) {
	path := "/diagnose/face-tongue/result/"
	marshal, err := json.Marshal(&req)
	if err != nil {
		return nil, err
	}
	fmt.Println(marshal)
	m := map[string]interface{}{
		"Authorization": "APPCODE " + s.AppCode,
	}
	response, err := utils.Common.PostCurl(marshal, url+path, m)
	return response, err
}
func (s *tencentStoreUtils) Report(req *model.ReqReport) ([]byte, error) {
	path := "/diagnose/face-tongue/report/"
	marshal, err := json.Marshal(&req)
	if err != nil {
		return nil, err
	}
	m := map[string]interface{}{
		"Authorization": "APPCODE " + s.AppCode,
	}
	response, err := utils.Common.PostCurl(marshal, url+path, m)
	return response, err
}
